package yang.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

import yang.pageModel.Menu;
import yang.pageModel.User;
import yang.service.MenuServiceI;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 
 * @ClassName: MenuAction
 * @Description: 树状菜单请求
 * @author: Administrator
 * @date: 2014年6月13日 上午8:44:37
 */
@Action(value = "menuAction")
public class MenuAction extends BaseAction implements ModelDriven<Menu> {

	private static final Logger logger = Logger.getLogger(MenuAction.class);

	private Menu menu = new Menu();

	private MenuServiceI menuService;

	public MenuServiceI getMenuService() {
		return menuService;
	}
	//--------get set ----------
	@Autowired
	public void setMenuService(MenuServiceI menuService) {
		this.menuService = menuService;
	}

	@Override
	public Menu getModel() {
		return menu;
	}

	/**
	 * 
	 * @Title: getTreeNode
	 * @Description: 异步获取节点的方法，没有使用
	 * @return: void
	 */
	public void getTreeNode() {
		super.writeJson(menuService.getTreeNode(menu.getId()));
	}
	/**
	 * 
	 * @Title: getAllTreeNode
	 * @Description: 按角色获取节点，没有关联数据库。
	 * @return: void
	 */
	public void getAllTreeNode() {
		String o="";
		User user= (User) ActionContext.getContext().getSession().get("user");
		
		if (user.getUserRole().equals("医生")) {
			o="zlgl";
		}else if (user.getUserRole().equals("前台")) {
			o="ghgl";
		}else if (user.getUserRole().equals("缴费")) {
			o="jfgl";
		}else if (user.getUserRole().equals("药房")) {
			o="yfgl";
		}else if (user.getUserRole().equals("管理员")) {
			o="yhgl";
		}else if (user.getUserRole().equals("超级管理员")) {
			o="";
		}else if (user.getUserRole().equals("财务")) {
			o="cwgl";
		}		
		logger.info(user.getUserRole()+"上班了");
		super.writeJson(menuService.getAllTreeNode(o));
		
	}

}
